package com.pig4cloud.pig.demo.Mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.pig4cloud.pig.demo.feign.Entity.Conlike;
import com.pig4cloud.pig.demo.feign.Entity.Userandlike;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserAndLikeMapper extends BaseMapper<Userandlike> {

    //    @Select("select * from userandlike where uid=#{uid} limit #{currentPage},#{size}")
//    @Results({
//            @Result(column = "uid", property = "uid"),
//            @Result(column = "is_liked", property = "isLiked"),
//            @Result(
//                    column = "cid",
//                    property = "conlike",
//                    javaType = Conlike.class,
//                    one = @One(select = "com.pig4cloud.pig.demo.Mapper.ConlikeMapper.findById")
//            )
//    })
    @Select("select * from userandlike where uid=#{uid} and cid=#{cid}")
    @Results({
            @Result(column = "uid", property = "uid"),
            @Result(column = "is_liked", property = "isLiked"),
            @Result(
                    column = "cid",
                    property = "conlike",
                    javaType = Conlike.class,
                    one = @One(
                            select = "com.pig4cloud.pig.demo.Mapper.ConlikeMapper.findById"
                    )
            )
    })
    public Userandlike findByUidAndCid(
            @Param("uid") Long uid,
            @Param("cid") Long cid);

    @Update("update userandlike set is_liked=#{is_liked} where uid=#{uid} and cid=#{cid}")
    public int updateByUidAndCid(
            @Param("uid") Long uid,
            @Param("cid") Long cid,
            @Param("is_liked") Integer is_liked
    );

    @Insert("insert into userandlike values(#{uid},#{cid},#{is_liked})")
    public int insertByUidAndCid(
            @Param("uid") Long uid,
            @Param("cid") Long cid,
            @Param("is_liked") Integer is_liked
    );
}
